
window.onload = function () {
    
    examTypeFoo();
    examTypeF();
    document.querySelector('.btn').addEventListener('click', function () {
        let stus = window.location.search
        let stu = stus.slice(stus.indexOf("?") + 1)
        window.location.href = `testPaper.html?${stu}`
    })
    // examTypeF()
}
let examTypeFoo = async () => {
    let result = await ajax({
        type: 'GET',
        url: 'http://127.0.0.1:4000/testPaper/GetTestPaperFind'
    })
    let resultJs = JSON.parse(result);
    let t = window.location.search;
    // console.log(t);
    let s = t.slice(t.indexOf("&") + 4)
    // console.log(s);
    for (let item of resultJs.obj) {
        if (s == item._id) {
           
            document.querySelector('.titles').innerHTML = item.title;
        }
    }
    examInfo(resultJs.obj);
}
let examTypeF = async () => {
    let res = await ajax({
        type: 'GET',
        url: 'http://127.0.0.1:4000/xgstudent/GetAllStudents'
    })
    let resJs = JSON.parse(res);

    //截取学生id

    let stuId = window.location.search
    let stu_id = stuId.slice(stuId.indexOf("?")+1, stuId.indexOf('='))
 
    for (let item of resJs.obj) {
     if (stu_id == item.phone) {
         setTimeout(() => {
                document.querySelector('.stuName').innerHTML = item.name;
            },200)
      
        }
    }
}

// console.log(stu_id);

function examInfo(x) {
    x.forEach(v => {
        let page = `
    <span>试卷信息</span>
    <ul class="title">
        <li>考试类型</li>
        <li>考试时间</li>
        <li>答卷时间</li>
        <li>考试方式</li>
    </ul>
    <ul class="render1"> 
        <li>正在考试</li>
        <li>${v.date}</li>
        <li>${v.time}</li>
        <li>线上</li>
    </ul>
`
        let page2 = `<span>考生信息</span>
<ul class="title">
    <li>姓名</li>
    <li>证件号码</li>
    <li>部门</li>
</ul>
<ul  class="render2">
    <li class="stuName">张三</li>
    <li>612722111122223456</li>
    <li>信息中心</li>
</ul>`
        document.querySelector('.part2').innerHTML = page;
        document.querySelector('.part3').innerHTML = page2;
    })

}


